package com.ruoyi.system.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.ConnDrawComponentinfo;
import com.ruoyi.system.service.GraphPDFService;
import com.ruoyi.system.service.IConnDrawComponentinfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/graph")
@Api(tags = "工程图纸pdf")
@Slf4j
public class GraphPDFController extends BaseController {

    @Autowired
    private GraphPDFService graphPDFService;

    @Autowired
    private IConnDrawComponentinfoService connDrawComponentinfoService;

    @PostMapping("/getGraphSvgXml")
    @ResponseBody
    @ApiOperation(value = "根据id生成完整的svg")
    public AjaxResult getGraphSvgXml(@RequestParam("graphId")String graphId) {
        return AjaxResult.success("操作成功",graphPDFService.getGraphSvgXml(graphId,0));
    }


    @GetMapping("/fdExportPDF")
    @ResponseBody
    @ApiOperation(value = "导出图纸为PDF文件")
    public void fdExportPDF(HttpServletResponse response,
                            @RequestParam("graphIds") String graphIds) {
            graphPDFService.exportGraph2PDF(response, graphIds);
    }

    @GetMapping("/svgToPDF")
    @ResponseBody
    @ApiOperation(value = "SVG转pdf文件")
    public void svgToPDF(String filePath) {
        graphPDFService.svgToPDF(filePath);
    }

    @GetMapping("/getFontSvg")
    @ResponseBody
    @ApiOperation(value = "svg测试图例文字")
    public void getFontSvg(String id) {
        ConnDrawComponentinfo conn = connDrawComponentinfoService.getById(id);
        graphPDFService.getFontSvg(conn.getComponentSvgXml(),0);
    }

    @GetMapping("/pdfMark")
    @ResponseBody
    @ApiOperation(value = "pdf标注")
    public void pdfMark(String instanceId) {
        graphPDFService.pdfMark(instanceId);
    }

}


